package org.jeecg.modules.chvegetable.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.oConvertUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.chvegetable.entity.FlowerTagBookpre;
import org.jeecg.modules.chvegetable.service.IFlowerTagBookpreService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
* @Description: 预出库台账
* @Author: jeecg-boot
* @Date:   2023-02-12
* @Version: V1.0
*/
@Slf4j
@Api(tags="预出库台账")
@RestController
@RequestMapping("/flower/flowerTagBookpre")
public class FlowerTagBookpreController extends JeecgController<FlowerTagBookpre, IFlowerTagBookpreService> {
   @Autowired
   private IFlowerTagBookpreService flowerTagBookpreService;

   /**
    * 分页列表查询
    *
    * @param flowerTagBookpre
    * @param pageNo
    * @param pageSize
    * @param req
    * @return
    */
   @AutoLog(value = "预出库台账-分页列表查询")
   @ApiOperation(value="预出库台账-分页列表查询", notes="预出库台账-分页列表查询")
   @GetMapping(value = "/list")
   public Result<?> queryPageList(FlowerTagBookpre flowerTagBookpre,
                                  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                  HttpServletRequest req) {
       QueryWrapper<FlowerTagBookpre> queryWrapper = QueryGenerator.initQueryWrapper(flowerTagBookpre, req.getParameterMap());
       Page<FlowerTagBookpre> page = new Page<FlowerTagBookpre>(pageNo, pageSize);
       LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipals().getPrimaryPrincipal();
       queryWrapper.inSql("storehouse","SELECT  b.code FROM  flower_storehouse b  LEFT JOIN flower_storehouse_detail c  on b.id = c.mainid  WHERE personid = '" + sysUser.getId() + "'" );
       IPage<FlowerTagBookpre> pageList = flowerTagBookpreService.page(page, queryWrapper);
       return Result.OK(pageList);
   }
   @ApiOperation(value="预出库台账-弹窗", notes="预出库台账-弹窗")
   @GetMapping(value = "/listDialog")
   public Result<?> listDialog(FlowerTagBookpre flowerTagBookpre,
                                  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                  HttpServletRequest req) {
       QueryWrapper<FlowerTagBookpre> queryWrapper = QueryGenerator.initQueryWrapper(flowerTagBookpre, req.getParameterMap());
       Page<FlowerTagBookpre> page = new Page<FlowerTagBookpre>(pageNo, pageSize);
       queryWrapper.gt("able_number",0);
       LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipals().getPrimaryPrincipal();
       queryWrapper.inSql("storehouse","SELECT  b.code FROM  flower_storehouse b  LEFT JOIN flower_storehouse_detail c  on b.id = c.mainid  WHERE personid = '" + sysUser.getId() + "'" );

       IPage<FlowerTagBookpre> pageList = flowerTagBookpreService.page(page, queryWrapper);
       return Result.OK(pageList);
   }
   /**
    * 通过id查询
    *
    * @param id
    * @return
    */
   @AutoLog(value = "预出库台账-通过id查询")
   @ApiOperation(value="预出库台账-通过id查询", notes="预出库台账-通过id查询")
   @GetMapping(value = "/queryById")
   public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
       FlowerTagBookpre flowerTagBookpre = flowerTagBookpreService.getById(id);
       return Result.OK(flowerTagBookpre);
   }

 /**
  * 导出excel
  *
  * @param request
  * @param flowerTagBookpre
  */
 @RequestMapping(value = "/exportXls")
 public ModelAndView exportXls(HttpServletRequest request, FlowerTagBookpre flowerTagBookpre) {
     return super.exportXls(request, flowerTagBookpre, FlowerTagBookpre.class, "预出库台账");
 }

 /**
  * 通过excel导入数据
  *
  * @param request
  * @param response
  * @return
  */
 @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
 public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
     return super.importExcel(request, response, FlowerTagBookpre.class);
 }

}
